home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8205 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  80 lines

  1. Path: monkeys.com!not-for-mail
  2. From: rfg@monkeys.com (Ronald F. Guilmette)
  3. Newsgroups: gnu.gcc.help,comp.lang.c
  4. Subject: Re: Is this a compiler bug?
  5. Date: 2 Mar 1996 02:48:27 -0800
  6. Organization: Infinite Monkeys & Co.
  7. Message-ID: <4h991r$qon@segfault.monkeys.com>
  8. References: <3135FEDB.65AA@carbon.chem.nyu.edu>
  9. NNTP-Posting-Host: segfault.monkeys.com
  10.  
  11. In article <3135FEDB.65AA@carbon.chem.nyu.edu>,
  12. Edward J. Huff <huffe@carbon.chem.nyu.edu> wrote:
  13. >The gcc documentation states:
  14. >> If the compiler does not produce an error message for invalid 
  15. >> input, that is a compiler bug. However, you should note that 
  16. >> your idea of "invalid input" might be my idea of "an extension"
  17. >> or "support for traditional practice".
  18. >
  19. >Is this a bug?  Or is it "support for traditional practice"?
  20. >
  21. >carbon% head static*.c
  22. >==> static_bug.c <==
  23. >static const char foo[];
  24. >
  25. >int
  26. >main(int argc, const char *argv[]) {
  27. >  printf("foo = '%s'\n",foo);
  28. >  return 0;
  29. >}
  30. >
  31. >#ifdef DEFINE_IT
  32. >static const char foo[] = "bar";
  33. >#endif
  34. >
  35. >==> static_bug2.c <==
  36. >const char foo[] = "baz";
  37. >carbon% gcc static*.c
  38. >carbon% a.out
  39. >foo = 'baz'
  40.  
  41. I believe that in this case, the proper ANSI required behavior would be to
  42. print:
  43.  
  44.     foo = ''
  45.  
  46. because there is some special clause in the C standard about tenative
  47. declarations (e.g. your first declaration of the `foo' array) and their
  48. handling at the end of a translation unit (i.e. `static_bug.c') in cases
  49. where no non-tenative declaration/definition has been provided... and that
  50. rule says that the compiler must act as if the data object in question
  51. has an initializer of zero.  Thus, I believe that the compiler should
  52. simulate the following definition at the end of the translation unit
  53. unit `static_bug.c':
  54.  
  55.     static const char foo[] = { 0 };
  56.  
  57. >carbon% gcc -DDEFINE_IT static*.c
  58. >carbon% a.out
  59. >foo = 'bar'
  60.  
  61. Obviously, GCC _is_ correctly handling this case.
  62.  
  63. >The IRIX C compiler gives an error:
  64. >
  65. >archimedes 23% cc static*.c
  66. >static_bug.c:
  67. >cfe: Error: static_bug.c, line 1: storage size for 'foo' isn't known
  68. > static const char foo[];
  69. > ------------------^
  70.  
  71. I don't think that is valid behavior for s standard conforming compiler.
  72. (See above.)
  73.  
  74. I suggest asking over in comp.std.c about this whole issue.
  75. -- 
  76.  
  77. -- Ron Guilmette, Roseville, CA -------- Infinite Monkeys & Co. ------------
  78. ---- E-mail: rfg@monkeys.com ----------- Purveyors of Compiler Test Suites -
  79. ------ Copyright (c) 1996 by Ronald F. Guilmette; All rights reserved. -----
  80.